package com.lb.shopguide.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.entity.market.TemplateTypeBean;

import java.util.List;

public class AdapterTemplateType extends BaseQuickAdapter<TemplateTypeBean, BaseViewHolder> {
    public AdapterTemplateType(int layoutResId, @Nullable List<TemplateTypeBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TemplateTypeBean item) {
        View view = helper.itemView;
        TextView tvTypeName = view.findViewById(R.id.tv_type_name);
        TextView tvTypeDesc = view.findViewById(R.id.tv_type_desc);
        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        tvTypeName.setText(item.getTypeName());
        tvTypeDesc.setText(item.getTypeTitle());

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        AdapterTemplate mAdapterTemplate = new AdapterTemplate(R.layout.item_template, item.getTemplateList());
        recyclerView.setAdapter(mAdapterTemplate);
        mAdapterTemplate.setOnUseTemplateClickListener(new AdapterTemplate.OnUseTemplateClickListener() {
            @Override
            public void onUseTemplateClick(String templateCode, String templateName) {
                if (mOnUseTemplateClickListener != null) {
                    mOnUseTemplateClickListener.onUseTemplateClick(templateCode, templateName);
                }
            }
        });
    }

    public interface OnUseTemplateClickListener {
        void onUseTemplateClick(String templateCode, String templateName);
    }

    public void setOnUseTemplateClickListener(OnUseTemplateClickListener listener) {
        this.mOnUseTemplateClickListener = listener;
    }

    private OnUseTemplateClickListener mOnUseTemplateClickListener;
}
